#include <linux/init.h>
#include <linux/module.h>
#include <linux/workqueue.h>
#include <linux/delay.h>

static struct delayed_work my_delayed_work;

// 工作函数
static void my_work_fn(struct work_struct *work)
{
    printk(KERN_INFO "Delayed work is running.\n");
}

static int __init my_module_init(void)
{
    // 初始化延迟工作
    INIT_DELAYED_WORK(&my_delayed_work, my_work_fn);

    // 安排延迟执行的工作，延迟 5 秒
    schedule_delayed_work(&my_delayed_work, msecs_to_jiffies(5000));

    printk(KERN_INFO "Module loaded. Work will run after 5 seconds.\n");
    return 0;
}

static void __exit my_module_exit(void)
{
    // 取消延迟工作
    cancel_delayed_work_sync(&my_delayed_work);

    printk(KERN_INFO "Module unloaded.\n");
}

module_init(my_module_init);
module_exit(my_module_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("A simple module to demonstrate schedule_delayed_work.");


